package com.example.permission.mapper;

import com.example.permission.entity.SystemRolePermission;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author qwer3
 * @version 1.0.0
 * @create 2025/11/16 11:45
 */
@Mapper
public interface SystemRolePermissionMapper {
    @Insert("""
<script>
insert into sys_role_permission (role_id, permission_id) 
values 
    <foreach collection='systemRolePermissions' item='rolePermission' separator=','>
        (#{rolePermission.roleId}, #{rolePermission.permissionId})
    </foreach>
</script>
""")
    void batchSaveRolePermission(List<SystemRolePermission> systemRolePermissions);

    @Select("""
select p.name from sys_role_permission rp
    left join sys_permission p on rp.permission_id = p.permission_id
where rp.role_id = #{roleId}
""")
    List<String> querySystemRoleDetailByRoleId(String roleId);

    @Delete("""
<script>
delete from sys_role_permission 
where role_id = #{roleId}
    and permission_id in
    <foreach collection="permissionIds" item="permissionId" open="(" separator="," close=")">
         #{permissionId}
    </foreach>
</script>
""")
    void batchRemoveRolePermission(@Param("roleId") String roleId,
                                   @Param("permissionIds") List<String> permissionIds);

    @Delete("""
delete from sys_role_permission where role_id = #{roleId}
""")
    void deleteRoleByRoleId(String roleId);
}
